<?php


namespace app\admin\model;
use app\admin\model\baseModel;
use app\admin\session\UserSession;
use think\facade\Request;

class admin_user extends baseModel
{
    public function roleuser(){
        return $this->belongsToMany('role','roleuser','uid','rid');
    }
    public function getRolePermission($id){
        $result = admin_user::with(['roleuser','roleuser.rolepermission'])->find($id);
        return $result;
    }

    //验证用户账号密码
    public function loginCheck(){
        $param    =    Request::param();
        $name     =    $param['name'];
        $passWord =   md5($param['password']);


        $result =$this->where('name',$name)->where('password',$passWord)->find();
        if(!$result){
            return '账号密码错误';
        }else{
            (new UserSession())->UserSessionSave($name,$passWord);
            return '登录成功';
        }
    }
}